unit ContainerUtils;

interface

uses
  Windows,
  Messages,
  SysUtils;

procedure CopyDataToContainer(hWindow: HWND; wmCmd: Integer; MsgStr: String; flgFocused: Boolean = True);

implementation

procedure CopyDataToContainer(hWindow: HWND; wmCmd: Integer; MsgStr: String; flgFocused: Boolean = True);
var
  len: Integer;
  cd: TCopyDataStruct;
  Msg: PChar;
begin
  len := Length(MsgStr) + 1;
  cd.dwData := wmCmd;
  cd.cbData := len;

  GetMem(Msg, len);
  try
    StrPCopy(Msg, MsgStr);
    cd.lpData := Msg;
    if flgFocused then
      SetForegroundWindow(hWindow);
    SendMessage(hWindow, WM_COPYDATA, 0, LParam(@cd));
  finally
    FreeMem(Msg, len);
  end;
end;

end.
